package com.spvs.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spvs.common.log.annotation.Log;
import com.spvs.common.log.enums.BusinessType;
import com.spvs.common.security.annotation.RequiresPermissions;
import com.spvs.system.domain.FileCommonPreview;
import com.spvs.system.service.IFileCommonPreviewService;
import com.spvs.common.core.web.controller.BaseController;
import com.spvs.common.core.web.domain.AjaxResult;
import com.spvs.common.core.utils.poi.ExcelUtil;
import com.spvs.common.core.web.page.TableDataInfo;

/**
 * 常用文件预览Controller
 *
 * @author supervision
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/preview")
public class FileCommonPreviewController extends BaseController
{
    @Autowired
    private IFileCommonPreviewService fileCommonPreviewService;

    /**
     * 查询常用文件预览列表
     */
    @RequiresPermissions("system:preview:list")
    @GetMapping("/list")
    public TableDataInfo list(FileCommonPreview fileCommonPreview)
    {
        startPage();
        List<FileCommonPreview> list = fileCommonPreviewService.selectFileCommonPreviewList(fileCommonPreview);
        return getDataTable(list);
    }

    /**
     * 导出常用文件预览列表
     */
    @RequiresPermissions("system:preview:export")
    @Log(title = "常用文件预览", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileCommonPreview fileCommonPreview)
    {
        List<FileCommonPreview> list = fileCommonPreviewService.selectFileCommonPreviewList(fileCommonPreview);
        ExcelUtil<FileCommonPreview> util = new ExcelUtil<FileCommonPreview>(FileCommonPreview.class);
        util.exportExcel(response, list, "常用文件预览数据");
    }

    /**
     * 获取常用文件预览详细信息
     */
    @RequiresPermissions("system:preview:query")
    @GetMapping(value = "/{previewId}")
    public AjaxResult getInfo(@PathVariable("previewId") Long previewId)
    {
        return success(fileCommonPreviewService.selectFileCommonPreviewByPreviewId(previewId));
    }

    /**
     * 新增常用文件预览
     */
    @RequiresPermissions("system:preview:add")
    @Log(title = "常用文件预览", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileCommonPreview fileCommonPreview)
    {
        return toAjax(fileCommonPreviewService.insertFileCommonPreview(fileCommonPreview));
    }

    /**
     * 修改常用文件预览
     */
    @RequiresPermissions("system:preview:edit")
    @Log(title = "常用文件预览", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileCommonPreview fileCommonPreview)
    {
        return toAjax(fileCommonPreviewService.updateFileCommonPreview(fileCommonPreview));
    }

    /**
     * 删除常用文件预览
     */
    @RequiresPermissions("system:preview:remove")
    @Log(title = "常用文件预览", businessType = BusinessType.DELETE)
	@DeleteMapping("/{previewIds}")
    public AjaxResult remove(@PathVariable Long[] previewIds)
    {
        return toAjax(fileCommonPreviewService.deleteFileCommonPreviewByPreviewIds(previewIds));
    }
}
